package datastructure.queue;

import java.util.Stack;

/**
 * Implement a Queue by two stacks
 * 
 * @author Lei
 */
public class QueueByTwoStacks {

    private Stack<Integer> in = new Stack<Integer>();
    private Stack<Integer> out = new Stack<Integer>();

    public void enqueue(int value) {
        while (!out.isEmpty()) {
            in.push(out.pop());
        }
        in.push(value);
    }

    public int dequeue() {
        while (!in.isEmpty()) {
            out.push(in.pop());
        }
        return out.pop();
    }
}
